package com.hnevc.chengzhihui;


import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;

import java.time.Instant;

public class MainActivity extends AppCompatActivity {

    private Button turnOnBtn;
    private Button turnOffBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();

    }
    public  void initView(){
        turnOnBtn = findViewById(R.id.turnOn_btn);
        turnOffBtn = findViewById(R.id.turnOff_btn);
    }
    private  void initData(){

    }
    public void initEvent(){
        turnOffBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //通过意图启动Service
                Intent intent =new Intent(MainActivity.this,MyService.class);
                startService(intent);

            }
        });
        turnOffBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,MyService.class);
                stopService(intent);
            }
        });
    }
}